# _*_coding : utf-8 _*_
# @Time : 2025/11/3 10:57
# @Author : Eavan
# @filename : test_Case_001.py

# 数据驱动

# import pytest
#
#
# class TestLogin:
#     @pytest.mark.parametrize(
#         "username,password,expected",  # 参数名
#         [
#             ('admin', '123456', True),
#             ('nasa', '123456', False),
#             ('bell', '123456', True),
#             ('admin', '123321', False)
#         ]
#     )
#     def test_login(self, username, password, expected):
#         """ 简单演示数据驱动 """
#         result = (username == 'admin' and password == '123456') or (username == 'bell' and password == '123456')
#         assert result == expected, f'登录验证失败{username}'

# import pytest, yaml, os
#
#
# def load_yaml_data(filename):
#     """ 从 yaml 文件读取测试数据 """
#     # __file__ 表示当前 py 文件路径
#     data_pass = os.path.join(os.path.dirname(__file__), filename)
#     with open(data_pass, encoding='utf-8') as f:
#         return yaml.safe_load(f)
#
#
# class TestLogin:
#     @pytest.mark.parametrize("case", load_yaml_data('nasa.yaml'))
#     def test_login_yaml(self, case):
#         """ 基于yaml文件实现数据驱动 """
#         username = case["username"]
#         password = case["password"]
#         expected = case["expected"]
#         result = (username == 'admin' and password == '123456') or (username == 'bell' and password == '123456')
#         # 断言验证
#         assert result == expected, f'登录验证失败 {case}'


import pytest


@pytest.fixture(params=[
    {"username": "admin", "password": "123456", "expected": True},
    {"username": "bell", "password": "123456", "expected": True}
])
def login_data(request):
    """ pytest.fixture 形式的数据返回"""
    return request.param

def test_login(login_data):
    username = login_data['username']
    password = login_data['password']
    expected = login_data['expected']
    result = (username == 'admin' and password == '123456') or (username == 'bell' and password == '123456')
    assert result == expected